<template>
  <div class="app-container doctor-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <router-link :to="{path:'/doctor/SaveUp'}">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            class="custom-button"
            v-hasPermi="['system:doctor:add']"
          >新增</el-button>
        </router-link>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          class="custom-button"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:doctor:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          class="custom-button"
          @click="handleExport"
          v-hasPermi="['system:doctor:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="doctorList"
      @selection-change="handleSelectionChange"
      class="custom-table"
      border
      stripe
      highlight-current-row>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="医生ID" align="center" prop="id" />
      <el-table-column label="医生照片" align="center" prop="dockerImage" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.dockerImage" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="所属医院院区ID" align="center" prop="hospitalName" />
      <el-table-column label="所属科室ID" align="center" prop="departmentName" />
      <el-table-column label="医生姓名" align="center" prop="name" />
      <el-table-column label="职称" align="center" prop="titleName" />
      <el-table-column label="医生简介" align="center" prop="intro" />
      <el-table-column label="专长" align="center" prop="specialty" />
      <el-table-column label="状态" align="center" prop="status" >
        <template slot-scope="scope">
            <span v-if="scope.row.status === 1">
              <el-button type="success" icon="el-icon-check" circle></el-button>
            </span>
          <span v-else>
              <el-button type="danger" icon="el-icon-close" circle></el-button>
            </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <router-link :to="{path:'/doctor/SaveUp',query: {index: scope.row.id}}">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              v-hasPermi="['system:doctor:edit']"
            >修改</el-button>
          </router-link>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:doctor:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
      class="custom-pagination"
    />
  </div>
</template>

<script>
import { listDoctor , delDoctor } from "@/api/system/doctor"

export default {
  name: "Doctor",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // k医生表格数据
      doctorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        hospitalareaId: [
          { required: true, message: "所属医院院区ID不能为空", trigger: "blur" }
        ],
        departmentId: [
          { required: true, message: "所属科室ID不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "医生姓名不能为空", trigger: "blur" }
        ],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询k医生列表 */
    getList() {
      this.loading = true
      listDoctor(this.queryParams).then(response => {
        this.doctorList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    // handleAdd() {
    //   this.reset()
    //   this.$router.push({
    //     name: 'SaveUp',
    //   })
    // },
    // /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset()
    //   const id = row.id || this.ids
    //   getDoctor(id).then(response => {
    //     this.$router.push({
    //       name: 'SaveUp',
    //       params: {
    //         leaderId:id,
    //       }
    //     })
    //
    //   })
    // },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除k医生编号为"' + ids + '"的数据项？').then(function() {
        return delDoctor(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/doctor/export', {
        ...this.queryParams
      }, `doctor_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style lang="scss" scoped>
.doctor-container {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 84px);

  .mb8 {
    margin-bottom: 20px;
    background: #fff;
    padding: 15px;
    border-radius: 4px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
  }

  .custom-button {
    transition: all 0.3s;
    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    }
  }

  .custom-table {
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;

    ::v-deep .el-table__header-wrapper {
      th {
        background-color: #f5f7fa;
        color: #606266;
        font-weight: 600;
      }
    }

    ::v-deep .el-table__row {
      &:hover {
        background-color: #f5f7fa !important;
      }
    }

    .el-button--text {
      padding: 0 5px;
      &:hover {
        color: #409EFF;
      }
    }
  }

  .custom-pagination {
    background: #fff;
    padding: 15px;
    border-radius: 4px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
  }

  .image-preview {
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  }
}
</style>
